package jm.mq.reject;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import jm.mq.utils.RabbitMQUtils;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.locks.LockSupport;

/**
 * @Description 死信队列生产者
 * @date 2022/3/9 10:57
 */
public class Producer {

    private static final String NORMAL_EXCHANGE = "e_ch1";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();
        // 声明交换机。
        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
        // 设置TTL时间存活时间 10 秒
        AMQP.BasicProperties properties =
                new AMQP.BasicProperties()
                .builder().expiration("10000").build();
        for (int i = 0; i < 11; i++) {
            String msg = "message" + i;
            channel.basicPublish(NORMAL_EXCHANGE,"zhangsan",properties,msg.getBytes(StandardCharsets.UTF_8));
            System.out.println("发送成功：" + msg);
        }
    }
}
